package com.tl.boot.main.hanlder;

import com.tl.boot.common.enums.ResultEnum;
import com.tl.boot.common.exception.BaseException;
import com.tl.boot.common.vo.ResponseVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * com.tl.boot.main.hanlder -- LocalExceptionHanlder
 * Description:
 * Created by joshua_liu <a href="mailto:joshualwork@163.com"></a>
 * On 2019/9/10 13:37
 */
@ControllerAdvice
@RestController
public class LocalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(LocalExceptionHandler.class);
    @ExceptionHandler(value = BaseException.class)
    public ResponseVO baseErrorHandler(BaseException e) {
        log.info("",e);
        return ResponseVO.buildFail(e.getErrorEnum());
    }

    @ExceptionHandler(value = Exception.class)
    public ResponseVO unknownErrorHandler(Exception e) {
        log.error("", e);
        return ResponseVO.buildFail(ResultEnum.SYSTEM_UNKNOWN);
    }
}
